﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using OrganizedIN.DAL;
using OrganizedIN.BAL;
using OrganizedIN.BussinessServices;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using OrganizedIN.BAL.Common;

namespace OrganizedIN.UI.Photos
{
    public partial class add_rating_photos : System.Web.UI.Page
    {
        string strUserName;

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string id = Request.QueryString["id"];
                strUserName = Convert.ToString(Session["UserID"]);

                if (!IsPostBack)
                {
                    DataSet ds = new DataSet();
                    ds = Common.getPhotoRate(strUserName, id);
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        dgRating.DataSource = ds.Tables[0];
                        dgRating.DataBind();
                        string rate = ds.Tables[0].Rows[0][2].ToString();
                        DropDownList ddl = (DropDownList)dgRating.Items[0].Cells[2].FindControl("ddlRating");
                        ddl.Items.FindByValue(rate).Selected = true;
                        
                    }
                    else
                    {
                        tddg.InnerHtml = "<h2>Sorry! No records found</h2>";
                    }
                }

            }
            catch (Exception ex)
            {
                tddg.InnerHtml = "<h2>Sorry! Some error occured</h2>";
            }
        }

        protected void dgRating_EditCommand(object sender, DataGridCommandEventArgs e)
        {
            try
            {
                int id = Convert.ToInt32(e.Item.Cells[0].Text);
                DropDownList ddlrate = (DropDownList)e.Item.Cells[2].FindControl("ddlRating");
                string rate = ddlrate.SelectedValue;
                DataSet ds = new DataSet();
                ds = Common.updatePhotoRating(strUserName, id, rate);
                Response.Redirect("myphotos.aspx");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
